package cn.south.campus.business.controller;

import cn.south.campus.business.model.req.LoginReq;
import cn.south.campus.business.model.vo.LoginVO;
import cn.south.campus.business.service.LoginService;
import cn.south.campus.common.model.bo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/13 10:07
 */
@RestController
@RequestMapping("/campus")
public class LoginController {
    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody @Valid LoginReq req) {
        return Result.success(loginService.login(req));
    }

    @PostMapping("logout")
    public Result<String> logout() {
        loginService.logout();
        return Result.success("退出成功");
    }
    @PostMapping("register")
    public Result<String> register(@RequestBody @Valid LoginReq req) {
        loginService.register(req);
        return Result.success("注册成功");
    }

    @GetMapping("userInfo")
    public Result<LoginVO> userInfo() {
        return Result.success(loginService.userInfo());
    }

}
